package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.Document;

import org.come.Frame.NPCJfram;
import org.come.Frame.ZhuFrame;
import org.come.bean.AllMapBean;
import org.come.bean.AllNpcBean;
import org.come.bean.GMshopItemBean;
import org.come.bean.HeadImgBean;
import org.come.bean.LoginResult;
import org.come.bean.NpcInfoBean;
import org.come.control.NpcMenuControl;
import org.come.entity.Goodstable;
import org.come.model.AllGMshopItem;
import org.come.model.Door;
import org.come.model.GMshopItem;
import org.come.model.Gamemap;
import org.come.model.Npctable;
import org.come.mouslisten.GoodsMouslisten;
import org.come.npc.TP;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.CutButtonImage;
import org.come.until.EquipTool;
import org.come.until.FormsManagement;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.NumberValidator;
import org.come.until.ScrenceUntil;
import org.come.until.ScrollUI;
import org.come.until.UserMessUntil;

import com.sun.org.apache.xpath.internal.operations.Number;
import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.RoleCaoZuoBtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

 

public class GMshopJpanel extends JPanel {
    private JLabel  labtext2, labtext3,// 
            labtext4;// 
	private static JLabel labtext5;
	private static JLabel labtext6;
	private static JLabel labtext1;
    private int day = 0;
    private static NPCJpanel npcJpanel;
    // 滚动条
    private static JScrollPane jScrollPane1, jScrollPane2;
    // 选中的地图
    private static DefaultListModel<String> pankModel,pankModel1;
    // 类型
    private static JList<String> listPank,listPank1;
    
    private static JTextField findName,findName1;
    
    private static RoleCaoZuoBtn sureGive, deleteGive;// 确定查询，取消
    
    private static String itemId = "";
    private static int number = 0;
    private static String itemName = "";
    private static boolean is = false;
    
    private Goodstable good;
    private static String[] Fvalue;
    private static JTextArea testMes;// 用来显示聊天信息
    public String npczb;
    public static String npcfeiji;
    // 排行榜信息表格中的对象
    private static DefaultTableModel tableModel;
    public GMshopJpanel() {

    		this.setPreferredSize(new Dimension(362, 308));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            findName = new JTextField();// 查询的物品名称输入
            findName.setBounds(138, 95, 128, 18);
            findName.setOpaque(false);
            findName.setBorder(BorderFactory.createEmptyBorder());
            findName.setForeground(Color.white);
            findName.setCaretColor(Color.white);
            findName.setFont(new Font("宋体",Font.PLAIN,15));
            this.add(findName);
            
            findName1 = new JTextField();// 查询的物品名称输入
            findName1.setDocument(new NumberValidator(2));
            findName1.setBounds(138, 164, 128, 18);
            findName1.setOpaque(false);
            findName1.setBorder(BorderFactory.createEmptyBorder());
            findName1.setForeground(Color.white);
            findName1.setCaretColor(Color.white);
            findName1.setFont(new Font("宋体",Font.PLAIN,15));
            this.add(findName1);

            Font font = new Font("楷体",Font.BOLD , 16);
            labtext5 = new JLabel();
            labtext5.setForeground(Color.BLACK);
            labtext5.setFont(font);
            labtext5.setBounds(70, 78, 250, 50);
            labtext5.setText("物品ID");
            this.add(labtext5);
            
            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 2000);
            offBtn.setBounds(362 - 25, 0, 25, 25);
            this.add(offBtn);
            font = new Font("楷体", Font.BOLD, 18);
            //
            
            
            labtext3 = new JLabel();
            labtext3.setForeground(Color.BLACK);
            labtext3.setFont(font);
            labtext3.setBounds(145, -10, 250, 50);
            labtext3.setText("物资发送");
//            this.add(labtext3);
            
            font = new Font("楷体", Font.BOLD, 16);
            
            labtext4 = new JLabel();
            labtext4.setForeground(Color.BLACK);
            labtext4.setFont(font);
            labtext4.setBounds(55, 115, 250, 50);
            labtext4.setText("物品名称");
            this.add(labtext4);
            
            labtext1 = new JLabel();
            labtext1.setForeground(Color.white);
            labtext1.setFont(font);
            labtext1.setBounds(138, 130, 128, 18);
            labtext1.setText("物品名字");
            this.add(labtext1);
//            if(dataNpcMapList!=null&& dataNpcMapList.size()>0) {
//            	getlisysta(dataNpcMapList);
//            }else {
//            	getlisysta(null);
//            }
            labtext5 = new JLabel();
            labtext5.setForeground(Color.BLACK);
            labtext5.setFont(font);
            labtext5.setBounds(55, 148, 250, 50);
            labtext5.setText("发送数量");
            this.add(labtext5);
            
            font = new Font("楷体", 0, 16);
            labtext6 = new JLabel();
            labtext6.setForeground(Color.red);
            labtext6.setFont(font);
            labtext6.setBounds(60, 25, 250, 50);
            LoginResult loginResult = RoleData.getRoleData().getLoginResult();
            String type = "";
            if(loginResult.getGmshoptype()!=null) {
            	if("1".equals(loginResult.getGmshoptype())) {
            		type = "体验版";
            	}else if("2".equals(loginResult.getGmshoptype())){
            		type = "豪华版";
            	}else if("3".equals(loginResult.getGmshoptype())){
            		type = "尊享版";
            	}else {
            		type = "未开通";
            	}
            }else {
        		type = "未开通";
        	}
            labtext6.setText("开通级别："+type);
            this.add(labtext6);
            
            
            font = new Font("楷体", 0, 14);
            labtext2 = new JLabel();
            labtext2.setForeground(Color.BLACK);
            labtext2.setFont(font);
            labtext2.setBounds(40, 230, 350, 50);
            labtext2.setText("提示：物品ID请详查群文件或者咨询群主！");
            this.add(labtext2);
            
            
            sureGive = new RoleCaoZuoBtn("skin/8100226/newbutton/B20.png",  1, "搜索", 2101, UIUtils.COLOR_BLACK);
            sureGive.setBounds(100, 200, 59, 24);
            this.add(sureGive);
            sureGive = new RoleCaoZuoBtn("skin/8100226/newbutton/B20.png",  1, "发送", 2102, UIUtils.COLOR_BLACK);
            sureGive.setBounds(220, 200, 59, 24);
            this.add(sureGive);

        
    }
    
    
    
    //
    
    private static void GMshopJpanel() {
		// TODO Auto-generated method stub
		
	}

    
    
    
	/** 查询确定 */
	public static String findEnsure() {
		if(findName.getText() == null || findName.getText().length() == 0) {
			ZhuFrame.getZhuJpanel().addPrompt2("请输入物品ID！");
			return null;
		}
		LoginResult loginResult = RoleData.getRoleData().getLoginResult();
		if(loginResult.getGmshoptype() == null || "".equals(loginResult.getGmshoptype())) {
			ZhuFrame.getZhuJpanel().addPrompt2("您还未开通特权请联系GM开通！");
			return null;
		}
		//总数据
		List<Map<String, Object>> dataNpcMapList = new ArrayList<Map<String, Object>>();
		
		//GMshopItem数据
		List<GMshopItem> itemList = new ArrayList<GMshopItem>();
		GMshopItemBean allGMshopItem = UserMessUntil.getAllGMshopItem();
		if(allGMshopItem!=null) {
			Map<BigDecimal, GMshopItem> item = allGMshopItem.getAllGMshopItem();
			for (Entry<BigDecimal, GMshopItem> entry : item.entrySet()) {
	            //system.out.println("key = " + entry.getKey() + ", value = " + entry.getValue());
	            itemList.add(entry.getValue());
	        }
		}
		//当前特权级别可用的数据
		List<GMshopItem> itemTypeList = new ArrayList<GMshopItem>();
		if(loginResult.getGmshoptype()!=null) {
			if(itemList!=null &&itemList.size()>0) {
				for(GMshopItem item:itemList) {
					if(Integer.parseInt(item.getShoptype())<=Integer.parseInt(loginResult.getGmshoptype())) {
						itemTypeList.add(item);
					}
				}
			}
		}
		
		if(itemTypeList!=null && itemTypeList.size()>0) {
			for(GMshopItem item:itemTypeList) {
				if(item.getShopId().equals(findName.getText())) {
					labtext1.setText(item.getShopName());
					itemId = item.getItemId();
					itemName=item.getShopName();
					is =true;
				}
			}
		}
		if(!is) {
			ZhuFrame.getZhuJpanel().addPrompt2("未查到该物品 或者 您的特权等级不够 请升级！");
			labtext1.setText("");
			findName.setText("");
			findName1.setText("");
			itemName="";
			return itemId = "";
		}
		//物品ID检索
		//检索后的总数据
		is=false;
		return itemId;
	}
	
	//发送物资
	public static List<Map<String, Object>> iWantToFly() {
		if(findName1.getText() == null || findName1.getText().length() == 0) {
			ZhuFrame.getZhuJpanel().addPrompt2("请输入数量！");
			return null;
		}else if(Integer.parseInt(findName1.getText())>999){
			ZhuFrame.getZhuJpanel().addPrompt2("最大不能超过999");
			return null;
		}
		Goodstable goodstable = UserMessUntil.getgoodstable(new BigDecimal(itemId));
		if(goodstable!=null) {
			boolean dj = EquipTool.isEquip(goodstable.getType());
			if(dj) {
				if(Integer.parseInt(findName1.getText())>1) {
					ZhuFrame.getZhuJpanel().addPrompt2("该道具不可叠加，每次只能发送数量不能超过1个！");
					return null;
				}
			}
		}
		LoginResult loginResult = RoleData.getRoleData().getLoginResult();
		if(loginResult.getGmshoptype() == null || "".equals(loginResult.getGmshoptype())) {
			ZhuFrame.getZhuJpanel().addPrompt2("您还未开通特权请联系GM开通！");
			return null;
		}
		number=Integer.parseInt(findName1.getText());
		if(itemId!=null && number>0) {
			String msg = itemId+","+number+","+itemName;
			SendMessageUntil.toServer(Agreement.getAgreement().GMshopItemAgreement(msg));
			labtext1.setText("");
			findName.setText("");
			findName1.setText("");
			itemName="";
			itemId="";
		}
		return null;
	}
	
	private static void GMshopJpanel(List<Map<String, Object>> dataNpcMapList) {
		// TODO Auto-generated method stub
		
	}

   
    
    private ImageIcon icon = CutButtonImage.getImage("inkImg/hongmu/2/GMWP.png", 362, 308);

    public static int getCurrentMonthDay() {
        Calendar a = Calendar.getInstance();

        a.set(Calendar.DATE, 1);

        a.roll(Calendar.DATE, -1);

        int maxDate = a.get(Calendar.DATE);

        return maxDate;

    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        	icon = CutButtonImage.getImage("inkImg/old/background/GMWP.png", 362, 308);
        	g.drawImage(icon.getImage(), 0, 0, 362, 308, this);
        
    }

    public DefaultTableModel getTableModel() {
        return tableModel;
    }

    public void setTableModel(DefaultTableModel tableModel) {
        GMshopJpanel.tableModel = tableModel;
    }
    
    public static JTextField getFindName() {
		return findName;
	}

	public static void setFindName(JTextField findName) {
		GMshopJpanel.findName = findName;
	}

	public static JTextField getFindName1() {
		return findName1;
	}

	public static void setFindName1(JTextField findName1) {
		GMshopJpanel.findName1 = findName1;
	}

	public Goodstable getGood() {
		return good;
	}

	public void setGood(Goodstable good) {
		this.good = good;
	}

	public String[] getFvalue() {
		return Fvalue;
	}

	public void setFvalue(String[] fvalue) {
		Fvalue = fvalue;
	}

	public JTextArea getTestMes() {
		return testMes;
	}

	public void setTestMes(JTextArea testMes) {
		GMshopJpanel.testMes = testMes;
	}
	
	
}
